import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import axios from 'axios'

const useCommonStore = defineStore('common', () => {
  const userList = ref([])
  const loadUsers = () => {
    return new Promise((resolve, reject) => {
      axios
        .get('/api/load_users.php')
        .then((response) => {
          if (response.data && response.data.length > 0) {
            userList.value = response.data
            console.log('loadUsers', response.data)
          } else {
            console.warning('loadUsers', response.data)
          }
          resolve(response.data)
        })
        .catch((error) => {
          console.error('loadUsers', error)
          reject(error)
        })
    })
  }
  return { userList, loadUsers }
})

export default useCommonStore
